#include <iostream>
#include <vector>
#include <algorithm>
#include <sys/time.h>

using namespace std;

int removeDuplicates(vector<int>& nums) 
{
  if(nums.size()<3)
    return nums.size();
  auto it = nums.begin();
  for(int i=2;i<nums.size();++i)
  {
    if(nums[i] == nums[i-2])
    {
      nums.erase(nums.begin()+i);
      i--;
    }
  }




  return (nums.size());
}



int main(int argc,char *argv[])
{

  vector<int> nums={1,1,1,2,2,3};

  struct  timeval    tv1,tv2;
  struct  timezone   tz;
  int time1 = gettimeofday(&tv1,&tz);

  //func();
  int ret = removeDuplicates(nums);

  int time2 = gettimeofday(&tv2,&tz);
  cout << "time consuming(local machine/leetcode server):"<<endl
    <<"leetcode server time consuming should be less than 500ms"<<endl
    << tv2.tv_usec - tv1.tv_usec <<"us/"<<0.11*( tv2.tv_usec - tv1.tv_usec )<<"ms"<< endl;

  cout<<"ret:"<<ret<<endl;



  return 0;
}
